	window.UEDITOR_HOME_URL = '/ueditor/';

	var $ = layui.$
		,tt = new Date().getTime()
		,head = $('head')
	,layedit = {
  	  obj: {},
  	  config: {tool:[],hideTool:[],height:300,uploadImage:{}},
  	  build: function(id,options={})
  	  {
  	  	  $.extend( this.config, options );
  	  	  var _this = $('#'+id),content = _this.val(),i = $('.layui-editor').length;i++;
  	  	  _this.after('<div id="editor'+i+'" class="layui-editor"></div>');

  	  	  if(this.config.uploadImage.url.indexOf("article") >= 0 ) {
  	  	  	  type = 'article';
  	  	  }
  	  	  if(this.config.uploadImage.url.indexOf("answer") >= 0 ) {
  	  	  	  type = 'answer';
  	  	  }
  	  	  if(this.config.uploadImage.url.indexOf("question") >= 0 ) {
  	  	  	  type = 'question';
  	  	  }
  	  	  UEDITOR_CONFIG.serverUrl = UEDITOR_CONFIG.serverUrl+'?type='+type;
  	  	  UEDITOR_CONFIG.initialFrameHeight = this.config.height;
  	  	  UEDITOR_CONFIG.textarea = 'content';
  	  	  
		    var editor = UE.getEditor('editor'+ i,{zIndex:800});
			editor.ready(function() {
				editor.setContent(content);
			});
			
		    this.obj[i] = {id:id,editor:editor};
		    return i;
  	  },
  	  set: function(options)
  	  {
  	  	  $.extend( this.config, options );
  	  },
  	  getContent: function(index)
  	  {
  	  	  return this.obj[index].editor.getContent();
  	  },
  	  getText: function(index)
  	  {
  	  	  return this.obj[index].editor.getContentTxt();
  	  },
  	  sync: function(index)
  	  {
  	  	  $('#'+this.obj[index].id).val(this.obj[index].editor.getContent());
  	  },
  	  getSelection: function(index)
  	  {
  	  	  return '';
  	  }
  };

$("<script></script>").attr({ src: '/ueditor/ueditor.config.js?v='+tt, type: 'text/javascript'}).appendTo(head);
$("<script></script>").attr({ src: '/ueditor/ueditor.all.min.js?v='+tt, type: 'text/javascript'}).appendTo(head);

layui.layedit = layedit;